define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/dyfz/awards/info/index' + location.search,
                    add_url: 'user/dyfz/awards/info/add',
                    edit_url: 'user/dyfz/awards/info/edit',
                    del_url: 'user/dyfz/awards/info/del',
                    multi_url: 'user/dyfz/awards/info/multi',
                    import_url: 'user/dyfz/awards/info/import',
                    table: 'user_dyfz_awards_info',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'user_id', title: __('User_id'), visible: false },
                        { field: 'userinfo.name', title: __('User_id') },
                        {
                            field: 'award_type', title: __('Award_type'), searchList: { "0": __('国家'), "1": __('省级'), "2": __('校级'), "3": __('院级') }, formatter: function (value, row, index) {
                                var color = '';
                                var text = '';

                                switch (value) {
                                    case '0':
                                        color = 'color:rgb(255, 43, 5)';  // 比如省级的颜色是红色
                                        text = __('国家');
                                        break;
                                    case '1':
                                        color = 'color:rgb(255, 153, 0)';  // 国家级的颜色是绿色
                                        text = __('省级');
                                        break;
                                    case '2':
                                        color = 'color:rgb(0, 187, 255)';  // 校级的颜色是蓝色
                                        text = __('校级');
                                        break;
                                    case '3':
                                        color = 'color:rgb(60, 255, 0)';  // 院级的颜色是金色
                                        text = __('院级');
                                        break;
                                    default:
                                        color = 'color: #000000';  // 默认颜色为黑色
                                        text = value;
                                }

                                return '<span style="' + color + '">' + text + '</span>';
                            }
                        },
                        { field: 'award_name', title: __('Award_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content },
                        { field: 'award_time', title: __('Award_time'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content },
                        { field: 'organizer', title: __('Organizer'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content },
                        { field: 'award_image', title: __('Award_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image },
                        { field: 'create_time', title: __('Create_time'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime, visible: false },
                        { field: 'update_time', title: __('Update_time'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime, visible: false },
                        { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
